package com.onlineMIS.ORM.DAO.chainS.report.template;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;

import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Year;
import com.onlineMIS.ORM.entity.headQ.custMgmt.HeadQCust;
import com.onlineMIS.action.headQ.report.HqPeiHuoExpoertVO;
import com.onlineMIS.action.headQ.report.HqSalesStatisReportItem;
import com.onlineMIS.action.headQ.report.HqTabletReportItemVO;
import com.onlineMIS.ORM.entity.chainS.report.ChainSalesStatisReportItem;
import com.onlineMIS.ORM.entity.chainS.user.ChainStore;
import com.onlineMIS.ORM.entity.chainS.user.ChainUserInfor;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Brand;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Color;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Product;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.ProductBarcode;
import com.onlineMIS.ORM.entity.headQ.barcodeGentor.Quarter;
import com.onlineMIS.common.Common_util;
import com.onlineMIS.common.ExcelTemplate;
import com.onlineMIS.common.loggerLocal;

public class HqTabletReportTemplate  extends ExcelTemplate{
	private List<HqPeiHuoExpoertVO> items = new ArrayList<HqPeiHuoExpoertVO>();
	private int data_row = 4;

	private HeadQCust cust;
	private Date startDate = new Date();
	private Date endDate = new Date();



    public HqTabletReportTemplate(File file) throws IOException{
    	super(file);
    }
	
	public HqTabletReportTemplate(List<HqPeiHuoExpoertVO> items, HeadQCust cust, String templateWorkbookPath, Date startDate, Date endDate) throws IOException{
		super(templateWorkbookPath);
		this.items = items;
		this.cust = cust;
		this.startDate = startDate;
		this.endDate = endDate;
	}
	
	/**
	 *  this is the function to inject the inventory order to Jinsuan order template
	 * @return
	 */
	public HSSFWorkbook process(){
		
		//@总数sheet 1
		HSSFSheet sheet = templateWorkbook.getSheetAt(0);
		//write header
		Row header1 = sheet.getRow(1);
		header1.createCell(1).setCellValue(Common_util.dateFormat_f.format(startDate));
		header1.createCell(3).setCellValue(Common_util.dateFormat_f.format(endDate));
		
		Row header2 = sheet.getRow(2);
		header2.createCell(1).setCellValue(cust.getName());
		
		
		//write product infmration
		int totalDataRow = items.size();
		 int quantity = 0;//选货数量
		 int quantityPei = 0;//配货数量
		 int noQuantityPei = 0;//未配数量

		for (int i = 0; i < totalDataRow; i++){

			HqPeiHuoExpoertVO itemVO = items.get(i);
			Row row = sheet.createRow(data_row + i);
			row.createCell(0).setCellValue(itemVO.getOrderDateTime());
			row.createCell(1).setCellValue(itemVO.getPeihuoDateTime());
			row.createCell(2).setCellValue(itemVO.getCustName());
			row.createCell(3).setCellValue(itemVO.getBarcode());
			row.createCell(4).setCellValue(itemVO.getProductCode());
			row.createCell(5).setCellValue(itemVO.getColor());
			row.createCell(6).setCellValue(itemVO.getBrand());
			row.createCell(7).setCellValue(itemVO.getQuarter());
			row.createCell(8).setCellValue(itemVO.getCategoryLevel1());
			row.createCell(9).setCellValue(itemVO.getCategory());

			row.createCell(10).setCellValue(itemVO.getQuantity());
			quantity +=itemVO.getQuantity();
			
			row.createCell(11).setCellValue(itemVO.getQuantityPei());
			quantityPei +=itemVO.getQuantityPei();
			
			row.createCell(12).setCellValue(itemVO.getNoQuantityPei());
			noQuantityPei +=itemVO.getNoQuantityPei();
			
		}
		
		//把总数放进去
		Row row = sheet.createRow(data_row + totalDataRow);
		row.createCell(1).setCellValue("总计");
		row.createCell(9).setCellValue(quantity);
		row.createCell(10).setCellValue(quantityPei);
		row.createCell(11).setCellValue(noQuantityPei);
		
		return templateWorkbook;
	}
	

}
